
import javax.bluetooth.*;
import java.util.Vector;

public class BlueListener implements DiscoveryListener
{
    
// 4 interfaces that must be implemented:
// void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) 
// void inquiryCompleted(int discType) 
// void servicesDiscovered(int transID, ServiceRecord[] servRecord) 
// void serviceSearchCompleted(int transID, int respCode) 


    public Vector deviceVector = new Vector();
    
    public void deviceDiscovered(RemoteDevice device, DeviceClass cod) {
        String friendlyName = "[null]";

        try { 
            if (deviceVector.contains(device)==false) {
                deviceVector.addElement(device);
                friendlyName = device.getFriendlyName(false);
                System.out.println(">> found device: " + friendlyName
                	+ "  address: "+ device.getBluetoothAddress());
            }
            // else this is duplicated
        } catch (Exception e) {
            System.err.println("ex  deviceDiscovered: " + e);
        }
    }


    public void inquiryCompleted(int discType) {
        synchronized(this) {
            notify();
        }

        switch (discType) {
            case INQUIRY_COMPLETED:
            System.out.println("inquery completed");
            break;


            case INQUIRY_ERROR:
            System.out.println("inquery error");
            break;

            case INQUIRY_TERMINATED:
            System.out.println("inquiry terminated");
            break;

            default:
            System.out.println("inquiry unknown status: " + discType);
            break;

        }
    }
            

    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
        System.out.println("TODO: servicesDiscovered: transID=" + transID);
    }

    public void serviceSearchCompleted(int transID, int respCode) {
        System.out.println("TODO: servicesSearchCompleted: transID=" 
        + transID + "  respCode=" + respCode);
    }

}
